package com.ldk.base.framework.util.push;

import java.util.Properties;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;

import com.ldk.base.framework.util.ConvertUtil;
import com.ldk.base.framework.util.PropertiesUtil;

/**
 * 
 * @author xiangwl
 * 2017年4月20日
 * com.ldk.base.framework.util.push
 * JPushDispatcherBean
 */
public class JPushDispatcherBean implements InitializingBean, ApplicationListener<ApplicationEvent>{

	@Override
	public void onApplicationEvent(ApplicationEvent event) {
		
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		String cfgPath = this.getClass().getResource("/").getPath() + "/push.properties";
		Properties cfgProps = PropertiesUtil.read(cfgPath);
		//push参数配置
		String startup = PropertiesUtil.getProperty(cfgProps, "startup");
		Boolean usePush = ConvertUtil.parseBoolean(startup);
		if(usePush){
			String client_masterSecret = PropertiesUtil.getProperty(cfgProps, "client_masterSecret");
			String client_appKey  = PropertiesUtil.getProperty(cfgProps, "client_appKey");
			String server_masterSecret = PropertiesUtil.getProperty(cfgProps, "server_masterSecret");
			String server_appKey  = PropertiesUtil.getProperty(cfgProps, "server_appKey");
			//配置推送
			JPushDispatcher.getInstance().register("client", client_masterSecret, client_appKey, false);
			JPushDispatcher.getInstance().register("driver", server_masterSecret, server_appKey, false);
		}
	}

}
